package com.ruoyi.project.buildexperiment.mapper;

import com.ruoyi.project.buildexperiment.domain.AddExperimentParam;
import com.ruoyi.project.buildexperiment.domain.ExperimentDto;
import com.ruoyi.project.buildexperiment.domain.ExperimentParam;
import com.ruoyi.project.buildexperiment.domain.LabDto;
import com.ruoyi.project.myexperiment.domain.DetailsDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExperimentMapper {
    List<ExperimentDto> selectBuildexperiment(ExperimentParam experimentParam);

    @Select("select tl.id as labId,CONCAT(tl.lab_name,date_format(ld.order_time, '%Y-%m-%d'),'   (',tc.section,')   ') as labName,ld.id as section\n" +
            "from lab_subscribe ls \n" +
            "left join lab_date ld on ls.lab_date_id= ld.id \n" +
            "left join tb_lab tl on tl.id=ld.lab_id\n" +
            "left join tb_class_time tc on ld.classtime_id=tc.id\n" +
            "where ls.use_id=#{userId} and ls.status=1 and tl.lab_status=0 and ld.order_time>=DATE_FORMAT(Now(), '%Y-%m-%d')")
    List<LabDto> selectLab(@Param("userId") Long userId);


    @Insert("insert into \n" +
            "experiment_teach(experiment_name,course_id,lab_date_id,user_id,begin_time,end_time,\n" +
            "experiment_status,experiment_introduce,experiment_shape,create_time,accessory_id,online_id,experiment_type,accessory_path,allow)\n" +
            "VALUES\n" +
            "(#{experimentName},#{courseId},#{experimentLabId},#{userId},#{beginTime},#{endTime},0,#{experimentIntroduce},\n" +
            "#{experimentShape},NOW(),#{fileId},#{onlineId},#{experimentType},#{uploadPath},#{allow})")
    int insertExperiment(AddExperimentParam experimentParam);

    int issue(@Param("id") Long id);

    @Delete("delete from experiment_teach where id=#{id}")
    int deleteById(@Param("id")Long id);
    //同时删除学生提交实验的表
    @Delete("delete from student_experiment where id=#{id}")
    int deleteStuExById(@Param("id")Long id);

    //批量删除
    int deletes(String[] ids);
    //批量删除同样删除提交实验表
    int deletesStuExps(String[] ids);

    /**
     * 根据实验id查询实验
      * @param id
     * @return
     */
    ExperimentDto getExperimentDtoById(Long id);

    /**
     * 编辑实验
     */
    boolean updateExperiment(ExperimentDto experimentDto);

    /**
     * 编辑实验信息后，将学生提交实验表里的信息同步修改
     * @return
     */
    boolean updateStudentExperiment(DetailsDto detailsDto);


    /**
     * 查询实验类型
     */
    String selectType(ExperimentDto experimentDto);
    /**
     * 查询课程名字
     */
    String selectCourseName(ExperimentDto experimentDto);
    /**
     * 查询实验室信息
     */
    String selectExperimentMessage(ExperimentDto experimentDto);


    /**
     * 判断预约的实验室是否已经布置了实验
     * @param experimentLabId
     * @return
     */
    public Long ifExits(String experimentLabId);
}
